package com.edu.exam.entity.grading.export;

import com.edu.exam.entity.core.AuditableEntity;
import com.edu.exam.enums.system.RiskLevel;
import com.edu.exam.enums.grading.export.AuditType;
import com.edu.exam.enums.common.OperationType;
import com.edu.exam.enums.grading.export.OperationResult;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldDefaults;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;
import java.util.Map;

/**
 * 成绩导出审计表实体类
 *
 * <p>所属模块：B-06 成绩管理模块</p>
 * <p>对应数据库表：grade_export_audit</p>
 *
 * <p>成绩导出审计管理表，用于记录和分析成绩导出操作的审计信息。
 * 支持完整的操作追踪，包含操作记录、变更历史、安全审计、
 * 合规检查等功能。</p>
 *
 * <p>主要功能特性：</p>
 * <ul>
 *   <li>导出操作审计记录（用户、时间、操作类型等）</li>
 *   <li>数据访问审计追踪（查询、修改、删除等）</li>
 *   <li>权限变更审计记录</li>
 *   <li>系统配置变更审计</li>
 *   <li>安全事件记录和分析</li>
 *   <li>合规性检查和报告</li>
 * </ul>
 *
 * @author 系统生成
 * @version 1.0
 * @since 2025-11-10
 */
@Entity
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@FieldDefaults(level = AccessLevel.PRIVATE)
public class GradeExportAudit extends AuditableEntity {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    Long id;

    /**
     * 审计类型
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "audit_type", nullable = false, length = 30)
    AuditType auditType;

    /**
     * 操作类型
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "operation_type", nullable = false, length = 30)
    OperationType operationType;

    /**
     * 审计时间
     */
    @Column(name = "audit_time", nullable = false)
    LocalDateTime auditTime;

    /**
     * 操作用户ID
     */
    @Column(name = "user_id", nullable = false)
    Long userId;

    /**
     * 操作用户名
     */
    @Column(name = "username", nullable = false, length = 50)
    String username;

    /**
     * 用户真实姓名
     */
    @Column(name = "real_name", length = 50)
    String realName;

    /**
     * 用户部门ID
     */
    @Column(name = "department_id")
    Long departmentId;

    /**
     * 用户部门名称
     */
    @Column(name = "department_name", length = 100)
    String departmentName;

    /**
     * 用户角色
     */
    @Column(name = "user_role", length = 50)
    String userRole;

    /**
     * 客户端IP地址
     */
    @Column(name = "client_ip_address", length = 45)
    String clientIpAddress;

    /**
     * 客户端设备信息
     */
    @Column(name = "client_device_info", length = 200)
    String clientDeviceInfo;

    /**
     * 用户代理
     */
    @Column(name = "user_agent", length = 500)
    String userAgent;

    /**
     * 会话ID
     */
    @Column(name = "session_id", length = 100)
    String sessionId;

    /**
     * 请求ID
     */
    @Column(name = "request_id", length = 100)
    String requestId;

    /**
     * 目标对象ID
     */
    @Column(name = "target_id")
    Long targetId;

    /**
     * 目标对象类型
     */
    @Column(name = "target_type", length = 30)
    String targetType;

    /**
     * 目标对象名称
     */
    @Column(name = "target_name", length = 200)
    String targetName;

    /**
     * 目标对象标识
     */
    @Column(name = "target_identifier", length = 100)
    String targetIdentifier;

    /**
     * 操作描述
     */
    @Column(name = "operation_description", nullable = false, length = 500)
    String operationDescription;

    /**
     * 操作结果
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "operation_result", nullable = false, length = 20)
    OperationResult operationResult;

    /**
     * 操作前状态
     */
    @Column(name = "before_state", columnDefinition = "TEXT")
    String beforeState;

    /**
     * 操作后状态
     */
    @Column(name = "after_state", columnDefinition = "TEXT")
    String afterState;

    /**
     * 状态变更详情
     */
    @Column(name = "state_changes", columnDefinition = "TEXT")
    String stateChanges;

    /**
     * 操作参数
     */
    @Column(name = "operation_parameters", columnDefinition = "TEXT")
    String operationParameters;

    /**
     * 执行时间（毫秒）
     */
    @Column(name = "execution_time_ms")
    Long executionTimeMs;

    /**
     * 影响的数据行数
     */
    @Column(name = "affected_rows")
    Integer affectedRows;

    /**
     * 涉及的敏感数据类型
     */
    @Column(name = "sensitive_data_types", length = 200)
    String sensitiveDataTypes;

    /**
     * 数据访问范围
     */
    @Column(name = "data_access_scope", length = 200)
    String dataAccessScope;

    /**
     * 权限验证结果
     */
    @Column(name = "permission_check_result", length = 20)
    String permissionCheckResult;

    /**
     * 风险等级
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "risk_level", length = 20)
    RiskLevel riskLevel;

    /**
     * 安全评分
     */
    @Column(name = "security_score")
    Integer securityScore;

    /**
     * 异常标记
     */
    @Column(name = "anomaly_flag", nullable = false)
    Boolean anomalyFlag;

    /**
     * 异常描述
     */
    @Column(name = "anomaly_description", length = 500)
    String anomalyDescription;

    /**
     * 异常处理措施
     */
    @Column(name = "anomaly_actions", columnDefinition = "TEXT")
    String anomalyActions;

    /**
     * 合规性检查结果
     */
    @Column(name = "compliance_check_result", length = 20)
    String complianceCheckResult;

    /**
     * 合规性违规类型
     */
    @Column(name = "compliance_violation_type", length = 100)
    String complianceViolationType;

    /**
     * 业务规则验证结果
     */
    @Column(name = "business_rule_validation", length = 20)
    String businessRuleValidation;

    /**
     * 相关的审计ID
     */
    @Column(name = "related_audit_id")
    Long relatedAuditId;

    /**
     * 批处理操作ID
     */
    @Column(name = "batch_operation_id")
    String batchOperationId;

    /**
     * 父操作ID
     */
    @Column(name = "parent_operation_id")
    String parentOperationId;

    /**
     * 操作链路追踪
     */
    @Column(name = "operation_trace", length = 500)
    String operationTrace;

    /**
     * 系统模块
     */
    @Column(name = "system_module", length = 50)
    String systemModule;

    /**
     * 功能模块
     */
    @Column(name = "function_module", length = 50)
    String functionModule;

    /**
     * 接口名称
     */
    @Column(name = "interface_name", length = 100)
    String interfaceName;

    /**
     * 请求方法
     */
    @Column(name = "request_method", length = 10)
    String requestMethod;

    /**
     * 请求路径
     */
    @Column(name = "request_path", length = 200)
    String requestPath;

    /**
     * 响应状态码
     */
    @Column(name = "response_status_code")
    Integer responseStatusCode;

    /**
     * 错误信息
     */
    @Column(name = "error_message", columnDefinition = "TEXT")
    String errorMessage;

    /**
     * 错误堆栈
     */
    @Column(name = "error_stack_trace", columnDefinition = "TEXT")
    String errorStackTrace;

    /**
     * 操作备注
     */
    @Column(name = "operation_notes", length = 1000)
    String operationNotes;

    /**
     * 审计员备注
     */
    @Column(name = "auditor_notes", length = 1000)
    String auditorNotes;

    /**
     * 审计标签
     */
    @Column(name = "audit_tags", length = 300)
    String auditTags;

    /**
     * 扩展属性
     */
    @Column(name = "extension_attributes", columnDefinition = "TEXT")
    String extensionAttributes;

    /**
     * 创建人ID
     */
    @Column(name = "creator_id")
    Long creatorId;

    /**
     * 更新人ID
     */
    @Column(name = "updater_id")
    Long updaterId;

    /**
     * 创建时间
     */
    @CreationTimestamp
    @Column(name = "create_time", nullable = false, updatable = false)
    LocalDateTime createTime;

    /**
     * 更新时间
     */
    @UpdateTimestamp
    @Column(name = "update_time", nullable = false)
    LocalDateTime updateTime;

    /**
     * 版本号（乐观锁）
     */
    @Version
    @Column(name = "version")
    Long version;

    /**
     * 逻辑删除标记
     */
    @Column(name = "is_deleted", nullable = false)
    Boolean isDeleted;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    LocalDateTime deleteTime;

    /**
     * 删除人ID
     */
    @Column(name = "deleter_id")
    Long deleterId;

}
